﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

using CustomControlDatabaseInterface.Utilities;
using CustomControlDatabaseInterface.ViewModel.Interfaces;

namespace CustomControlDatabaseInterface.ViewModel
{
    public class CustomerDetailAddTechViewModel : CustomerDetailTechnologyViewModel
    {

        public ObservableCollection<String> AvailableTechs { get; set; }

        private String selectedTech; 
        public String SelectedTech {
            get {
                return this.selectedTech; 
            }
            set {
                if(value!= null)
                {
                    selectedTech = value;
                    OnPropertyChanged("SelectedTech");
                }
                
            }
        }

        public ICommand AddTechCommand { get; set; }

        public delegate void AddTechEventHandler(String control);

        public event AddTechEventHandler AddTech;

        public ICommand CancelCommand { get; set; }

        public delegate void CancelEventHandler();

        public event CancelEventHandler Cancel; 

        public CustomerDetailAddTechViewModel() {

            AvailableTechs = new ObservableCollection<string>();
            CancelCommand = new RelayCommand(param => OnCancelCommand());
            AddTechCommand = new RelayCommand(param => OnAddTechCommand());
        }

        public void InitializeOnAddTechViewModel(List<String> ImplementedTechs) {
            List<String> allTechs = DatabaseUtil.GetTableNames(); 
            UpdateObservableCollection(AvailableTechs, allTechs.Except(ImplementedTechs).ToList());
        }

        private void OnAddTechCommand() {
            AddTechEventHandler handler = AddTech;
            if (handler != null) {
                handler(SelectedTech);
            }
            
        }
        private void OnCancelCommand() {
            CancelEventHandler handler = Cancel; 
            if (handler != null) {
                handler();
            }
        }


    }
}
